package com.itheima.delaytask.feign.fallbackfactory;

import com.itheima.delaytask.dto.Task;
import com.itheima.delaytask.feign.TaskService;
import com.itheima.response.ResponseMessage;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Created by 传智播客*黑马程序员.
 */
@Component
@Slf4j
public class TaskServiceFallbackFactory implements FallbackFactory<TaskService> {
    @Override
    public TaskService create(Throwable throwable) {
        return new TaskService() {
            @Override
            public ResponseMessage push(Task task) {
                log.error("push task error by feign,task={},errormsg={}",task,throwable.getMessage());
                return ResponseMessage.error(null);
            }

            @Override
            public ResponseMessage poll(Integer type, Integer priority) {
                log.error("poll task error by feign,type={},priority={},errormasg={}",type,priority,throwable.getMessage());
                return ResponseMessage.error(null);
            }

            @Override
            public ResponseMessage cancel(Long taskId) {
                log.error("cancel task error by feign,taskId={},errormsg={}",taskId,throwable.getMessage());
                return ResponseMessage.error(false);
            }

            @Override
            public ResponseMessage refresh() {
                log.error("refresh by feign ,errormsg={}",throwable.getMessage());
                return ResponseMessage.error(null);
            }
        };
    }
}
